package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import com.manage.modules.dto.TBaseStationEquipHistorySelectDto;
import com.manage.modules.dto.TBaseStationEquipSelectDto;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseStationEquipHistoryVo;
import com.manage.modules.bo.TBaseStationEquipHistoryQueryBo;
import com.manage.modules.bo.TBaseStationEquipHistoryAddBo;
import com.manage.modules.bo.TBaseStationEquipHistoryEditBo;
import com.manage.modules.service.ITBaseStationEquipHistoryService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 设备历史Controller
 *
 * @author wx
 * @date 2021-08-13
 */
@Api(value = "设备历史控制器", tags = {"设备历史管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/equipHistory")
public class TBaseStationEquipHistoryController extends BaseController {

    private final ITBaseStationEquipHistoryService iTBaseStationEquipHistoryService;


    /**
     * 历史设备搜索下拉框
     *
     * @return
     */
    @GetMapping("/option")
    public AjaxResult option(TBaseStationEquipHistorySelectDto selectDto) {
        return AjaxResult.success(iTBaseStationEquipHistoryService.option(selectDto));
    }

    /**
     * 查询设备历史列表
     */
    @ApiOperation("查询设备历史列表")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseStationEquipHistoryVo> list(TBaseStationEquipHistoryQueryBo bo) {
        startPage();
        List<TBaseStationEquipHistoryVo> list = iTBaseStationEquipHistoryService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出设备历史列表
     */
    @ApiOperation("导出设备历史列表")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:export')")
    @Log(title = "设备历史", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseStationEquipHistoryVo> export(TBaseStationEquipHistoryQueryBo bo) {
        List<TBaseStationEquipHistoryVo> list = iTBaseStationEquipHistoryService.queryList(bo);
        ExcelUtil<TBaseStationEquipHistoryVo> util = new ExcelUtil<TBaseStationEquipHistoryVo>(TBaseStationEquipHistoryVo.class);
        return util.exportExcel(list, "设备历史");
    }

    /**
     * 获取设备历史详细信息
     */
    @ApiOperation("获取设备历史详细信息")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:query')")
    @GetMapping("/{equipHistoryId}")
    public AjaxResult<TBaseStationEquipHistoryVo> getInfo(@PathVariable("equipHistoryId") Long equipHistoryId) {
        return AjaxResult.success(iTBaseStationEquipHistoryService.queryById(equipHistoryId));
    }

    /**
     * 新增设备历史
     */
    @ApiOperation("新增设备历史")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:add')")
    @Log(title = "设备历史", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseStationEquipHistoryAddBo bo) {
        return toAjax(iTBaseStationEquipHistoryService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改设备历史
     */
    @ApiOperation("修改设备历史")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:edit')")
    @Log(title = "设备历史", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseStationEquipHistoryEditBo bo) {
        return toAjax(iTBaseStationEquipHistoryService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除设备历史
     */
    @ApiOperation("删除设备历史")
    @PreAuthorize("@ss.hasPermi('modules:equipHistory:remove')")
    @Log(title = "设备历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipHistoryIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] equipHistoryIds) {
        return toAjax(iTBaseStationEquipHistoryService.deleteWithValidByIds(Arrays.asList(equipHistoryIds), true) ? 1 : 0);
    }
}
